{include file="public/head"}
<style>
    .x-body {
        min-width: 1200px;
    }

    body {
        overflow-x: scroll;
    }
    a {
        cursor:pointer;
    }
</style>
<body>
<div class="x-body">
    <div class="lotus-nav">
        <input type="hidden" id="company_id" name="company_id" value="{$Think.get.company_id}">
        {if empty($Think.get.company_id)}
        <button class="layui-btn layui-btn-sm"
                onclick="x_admin_show('添加分类','addCategory.html?company_id={$Think.get.company_id}',500)">
            <i class="layui-icon layui-icon-add-circle"></i>新建
        </button>

        <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除
        </button>
        {/if}
        <span class="x-right">共有数据:<i class="i_count">{$bcategory->total()}</i>条
            <button onclick="javascript:location.reload()" class="layui-btn-default ">
                <i class="layui-icon layui-icon-refresh"></i>
            </button>
        </span>
    </div>


    <table class="layui-table">
        <thead>
        <tr>
            <th style="width: 45px;text-align: center">
                <div class="header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>任务名称</th>
            <th>智赢分类</th>
            <th style="width: 70px;text-align: center">采集平台</th>
            <th style="width: 120px;text-align: center">采集用户</th>
            <th style="width: 85px;text-align: center">操作</th>
        </thead>
        <tbody>

        {volist name="bcategory" id="vo"}
        <tr>
            <td>
                <div class="layui-form-checkbox" lay-skin="primary" data-id='{$vo.id}'>
                    <i class="layui-icon">&#xe605;</i>
                </div>{$i}
            </td>
            <td>{$vo.bname}</td>
            <td>{$vo.zycategory}</td>
            <td style="text-align: center">{$vo.platform}</td>
            <td style="text-align: center">{$vo.truename}</td>
            <td style="text-align: center">
                {if empty($Think.get.company_id)}
                <button class="layui-btn layui-btn-xs"
                        onclick="x_admin_show('编辑分类','editCategory.html?id={$vo.id}','500')">编辑
                </button>
                <button onclick="del(this,'{$vo.id}','{$vo.bname}','{$vo.platform}','{$vo.user_name}',{$productNum[$vo['id']]|default='0'})"
                        class="layui-btn layui-btn-xs layui-btn-danger">删除
                </button>
                {else/}
                <button class="layui-btn layui-btn-sm layui-btn-disabled">暂无操作权限</button>
                {/if}
            </td>
        </tr>
        {/volist}

        </tbody>
    </table>
    <div class="page">
        <div>
            {$bcategory->render()}
        </div>
    </div>
</div>
</body>
{include file="public/foot"}
<script>
    function search() {
        var proname = $("#proname").val();
        var code = $("#code").val();
        var platformStr = $("#platform").val();
        var lanid = $("#lang").val();
        var company_id = $("#company_id").val();
        if (proname || code ) {
            p_admin_show("产品列表","productListCollect.html?proname=" + proname + "&code=" + code + "&platformStr=" + platformStr + "&lanid=" + lanid + "&company_id=" + company_id);
        } else {
            location.href = "index.html?platformStr=" + platformStr + "&lanid=" + lanid + "&company_id=" + company_id;
        }
    }


    function del(obj, id, bname, platform, user_name, num) {
        var count = $(".i_count")[0].innerText;
        var msg = num > 0 ? '此分类下存在产品信息，是否继续确认删除？' : '确认要删除吗？';
        layer.confirm(msg, {icon: 0, title: '提示'}, function (index) {
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/product/delCategory')}", {
                id: id,
                bname: bname,
                platform: platform,
                user_name: user_name
            }, function (data, textStatus, xhr) {
                console.log(data);
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(obj).parents('tr').remove();
                        $(".i_count").html(count - 1);
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }

    //删除所有
    function delAll() {
        var count = $(".i_count")[0].innerText;
        var data = tableCheck.getData();
        var length = data.length;
        if (length == 0) {
            layer.msg("请选择需要删除的分类");
            return false;
        }
        layer.confirm('此操作将会删除分类下所有产品信息，是否继续确认删除？', {icon: 0, title: '提示'}, function (index) {
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/product/delCategory')}", {ids: data}, function (data, textStatus, xhr) {
                /*optional stuff to do after success */
                console.log(data);
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                        $(".i_count").html(count - length);
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }
    function p_admin_show(title,url){
        layer.open({
            type: 2,
            area: ['100%', '100%'],
            fix: false, //不固定
            maxmin: true,
            shadeClose: false,//是否点击遮罩关闭弹窗
            shade:0.2,
            resize:true,
            title: title,
            content: url
        });
    }
</script>
